import './assets/main.scss'
import '@/types/index.ts'
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { createPinia } from 'pinia'
const pinia = createPinia();
import '@/styles/element.scss'
import ElementPlus from 'element-plus'
import axios from 'axios'
import url from "@/utils/url.ts"
import request from "@/utils/request.ts"
import MessageBox from "@/utils/MessageBox.ts"
import common from "@/utils/common.ts"
import utils from "@/utils/utils.ts"
import DialogBox from "@/utils/DialogBox.ts"
import pageFiles from "@/utils/pageFiles.ts"
import zhLocale from 'element-plus/es/locale/lang/zh-cn';



/** 全局组件声明 */
const baseComponents = {
  SearchHeader: () => import('@/components/Header/SearchHeader.vue'),
  ContainerBody: () => import('@/components/Container/ContainerBody.vue'),
  DatePicker: () => import('@/components/funcUnit/DatePicker.vue'),
  uploadFileInput: () => import('@/components/funcUnit/uploadFileInput.vue'),
  uploadFile: () => import('@/components/funcUnit/uploadFile.vue'),
  uploadImageInput: () => import('@/components/funcUnit/uploadImageInput.vue'),
  uploadImage: () => import('@/components/funcUnit/uploadImage.vue'),
  RadioUnit: () => import('@/components/funcUnit/RadioUnit.vue'),
  selectDept: () => import('@/components/funcUnit/selectDept.vue'),
  MchtInfoViewPic: () => import('@/components/funcUnit/MchtInfoViewPic.vue'),
  pagination: () => import('@/components/funcUnit/pagination.vue'),
}

const app = createApp(App)
/** 注册自定义指令 v-prevent-reclick 防重复点击 */
app.directive('prevent-reclick', {
  beforeMount(el, binding) {
    el.disabled = false; // 初始化时启用按钮
    el.addEventListener('click', () => {
      el.disabled = true; // 点击后禁用按钮
      setTimeout(() => {
        el.disabled = false; // 在指定的时间后重新启用按钮
      }, binding.value || 2000); // 使用 binding.value 来设置等待时间，默认为 2000 毫秒
    });
  },
  unmounted(el) {
    // 组件卸载时移除事件监听器
    if (el.hander) {
      el.removeEventListener('click');
    }
  },
});
/** 自定义指令 v-table-fix 表格高度自适应 */
app.directive('table-fix', {
  updated(el) {
    const height = window.innerHeight - el.getBoundingClientRect().top - 88 + 'px'    
    el.style.height = height;
  },
  unmounted(el) {
    el.style.height = '0px';
  },
});
app.config.warnHandler = () => null
// element-plus按需引入方式下，全局修改组件大小
app.config.globalProperties.$ELEMENT = {
  size: 'small'
}
for (const [componentName, component] of Object.entries(baseComponents)) {
  app.component(componentName, component)
}

/** 挂载到全局（方法-规则） */
app.provide('$axios', axios);
app.provide('$url', url);
app.provide('$request', request);
app.provide('$common', common);
app.provide('$utils', utils);
app.provide('$MessageBox', MessageBox);
app.provide('$DialogBox', DialogBox);
app.provide('$pageFiles', pageFiles);



app.use(pinia)
app.use(ElementPlus, {locale:zhLocale})
app.use(router)

app.mount('#app')
